﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Itop.GpsCar.Model;

namespace Itop.GpsCar.Web.MainMap
{
    public partial class map : System.Web.UI.Page
    {
        public bool DrawLine = false;
        public class MapPoint
        {
            public MapPoint(double jd, double wd)
            {
                x = jd;
                y = wd;
            }
            public double x;
            public double y;
            public string pl = "0";
            public double speed = 0;
            public string strTime = "00:00:00";
        }
        public static IList<MapPoint> marlist = new List<MapPoint>();
        public static IList<MapPoint> pointlist = new List<MapPoint>();
        protected void Page_Load(object sender, EventArgs e)
        {
            marlist.Clear();
            System.Collections.Generic.IList<device> mList = Global.SqlMapper.GetList<device>(null);
            foreach (device de in mList)
            {
                position pos = new position();
                pos.device_id = de.device_id;
                System.Collections.Generic.IList<devicecarrier> devicecarrierList = Global.SqlMapper.GetList<devicecarrier>("SelectdevicecarrierList", " where device_id = " + de.device_id);
                System.Collections.Generic.IList<position> posList = Global.SqlMapper.GetList<position>("SelectpositionList", " where device_id = " + de.device_id + " order by timestamp desc");
                if (posList.Count > 0)
                {

                    MapPoint mp = new MapPoint(posList[0].latitude, posList[0].longitude);
                    mp.speed = posList[0].speed;
                    mp.strTime = posList[0].timestamp.ToString();
                    if (devicecarrierList.Count>0)
                    {
                        object car = Global.SqlMapper.GetObject("SelectcarrierList", " where idCarrier = " + devicecarrierList[0].carrier_id);
                        if (car != null)
                        {
                            mp.pl = (car as carrier).plate;
                        }
                        else
                        {
                            mp.pl = "0";
                        }
                    }
                    else
                    {
                        mp.pl = "0";
                    }

                    marlist.Add(mp);
                }
            }
        }
    }
}
